package com.sun.module_common.sp

import com.sun.module_base.store.DataStoreUtils
import com.sun.module_base.utils.fromJson
import com.sun.module_base.utils.toJson
import com.sun.module_common.model.UserInfo

/**
 *@author:sunc
 *@time :2025/7/21 14:26
 *@desc: 用户数据存储
 */
object SpUtils {

    var isLogin: Boolean
        get() = DataStoreUtils.readBooleanData("isLogin", false)
        set(value) = DataStoreUtils.saveSyncBooleanData("isLogin", value = value)

    var isAgree: Boolean
        get() = DataStoreUtils.readBooleanData("isAgree", false)
        set(value) = DataStoreUtils.saveSyncBooleanData("isAgree", value = value)

    var userInfo: UserInfo?
        get() = DataStoreUtils.readStringData("userInfo").fromJson()
        set(value) = DataStoreUtils.saveSyncStringData("userInfo", value = value?.toJson() ?: "")
}